<?php
  function contact_form_validation($form) {


	// minimum length charcter
  	minilength_validation($form['title']['#value'], 5, $form['title']['#title'], 'title');
	minilength_validation($form['field_cont_desg']['und'][0]['value']['#value'], 5, $form['field_cont_desg']['und'][0]['value']['#title'],'field_cont_desg');
	minilength_validation($form['field_cont_post']['und'][0]['value']['#value'], 5, $form['field_cont_post']['und'][0]['value']['#title'],'field_cont_post');

	 // Bad character validations

  chkbadchar($form['title']['#value'], $form['title']['#title'], 'title');
  chkbadchar($form['field_cont_desg']['und'][0]['value']['#value'], $form['field_cont_desg']['und'][0]['value']['#title'],'field_cont_desg');
  badurl($form['field_website']['und'][0]['value']['#value'], $form['field_website']['und'][0]['value']['#title'],'field_website');

	// Email

	isValidEmail($form['field_cont_email']['und'][0]['value']['#value'],$form['field_cont_email']['und'][0]['value']['#title'],'field_cont_email');

	//phone code

	codenumber($form['field_cont_phone1']['und'][0]['value']['#value'],$form['field_cont_phone1']['und'][0]['value']['#title'],'field_cont_phone1');
	startcode($form['field_cont_phone1']['und'][0]['value']['#value'],$form['field_cont_phone1']['und'][0]['value']['#title'],'field_cont_phone1');


	codenumber($form['field_cont_phone2']['und'][0]['value']['#value'],$form['field_cont_phone2']['und'][0]['value']['#title'],'field_cont_phone2');
	startcode($form['field_cont_phone2']['und'][0]['value']['#value'],$form['field_cont_phone2']['und'][0]['value']['#title'],'field_cont_phone2');


	// phone number
	//check_integer($form['field_cont_phone']['und'][0]['value']['#value'],$form['field_cont_phone']['und'][0]['value']['#title'],'field_cont_phone');
	check_integer($form['field_cont_phone1']['und'][0]['value']['#value'],$form['field_cont_phone1']['und'][0]['value']['#title'],'field_cont_phone1');
	minilength_validation($form['field_cont_phone']['und'][0]['value']['#value'], 6, $form['field_cont_phone']['und'][0]['value']['#title'],'field_cont_phone');

	//check_integer($form['field_cont_landline']['und'][0]['value']['#value'],$form['field_cont_landline']['und'][0]['value']['#title'],'field_cont_landline');
	check_integer($form['field_cont_phone2']['und'][0]['value']['#value'],$form['field_cont_phone2']['und'][0]['value']['#title'],'field_cont_phone2');
	minilength_validation($form['field_cont_landline']['und'][0]['value']['#value'], 6, $form['field_cont_landline']['und'][0]['value']['#title'],'field_cont_landline');
	//maxlength_validation($form['field_cont_landline']['und'][0]['value']['#value'], 8, $form['field_cont_landline']['und'][0]['value']['#title'],'field_cont_landline');

	//mobile no
	check_integer($form['field_cont_mobile']['und'][0]['value']['#value'],$form['field_cont_mobile']['und'][0]['value']['#title'],'field_cont_mobile');
	maxlength_validation($form['field_cont_mobile']['und'][0]['value']['#value'], 13, $form['field_cont_mobile']['und'][0]['value']['#title'], 'field_cont_mobile');
	minilength_validation($form['field_cont_mobile'][0]['value']['#value'], 10, $form['field_cont_mobile']['#title'],'field_cont_mobile');
	mobilecode($form['field_cont_mobile']['und'][0]['value']['#value'],$form['field_cont_mobile']['und'][0]['value']['#title'],'field_cont_mobile');

	//Fax code
	codenumber($form['field_cont_cfax']['und'][0]['value']['#value'],$form['field_cont_cfax']['und'][0]['value']['#title'],'field_cont_cfax');
	startcode($form['field_cont_cfax']['und'][0]['value']['#value'],$form['field_cont_cfax']['und'][0]['value']['#title'],'field_cont_cfax');

	//Fax Number
        //check_integer($form['field_cont_fax']['und'][0]['value']['#value'],$form['field_cont_fax']['und'][0]['value']['#title'],'field_cont_fax');

	// Pin Code  field_cont_state[value]
        //echo $form['field_cont_state']['value']['#value'];
	chkcharpincode($form['field_cont_pincode']['und'][0]['value']['#value'],$form['field_cont_pincode']['und'][0]['value']['#title'],'field_cont_pincode');
	startpincode($form['field_cont_pincode']['und'][0]['value']['#value'],$form['field_cont_pincode']['und'][0]['value']['#title'],$form['field_cont_state']['und'][0]['value']['#value'],'field_cont_pincode');
	check_integer($form['field_cont_pincode']['und'][0]['value']['#value'],$form['field_cont_pincode']['und'][0]['value']['#title'],'field_cont_pincode');


	// Date Validation

    check_scheduler_date_expire($form['scheduler_settings']['unpublish_on']['date']['#value'],'unpublish_on');
	check_date_expire($form['field_retire_date']['und'][0]['value']['date']['#value'],$form['field_retire_date']['und'][0]['#title'],'field_retire_date');
	// Pin code

	maxlength_validation($form['field_cont_pincode']['und'][0]['value']['#value'], 6, $form['field_cont_pincode']['und'][0]['value']['#title'], 'field_cont_pincode');
  }

  /*function contact_load_validation() {
    $stat = new set_static_variable();
    $stat->set_edit('yes');
  }*/

  /*function contact_form_validation($form) {
    valid_email_address($form['field_cont_email'][0]['value']['#value']);
  }*/

  function contact_presave_validation($node) {
    $reference_url = $node->field_cont_url['und'][0]['value'];
    $node->field_cont_url[0]['value'] = url_validation($reference_url);
  }
